package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.EPWireDao;
import com.hongxun.modules.eys.entity.EPWireEntity;
import com.hongxun.modules.eys.service.EPWireService;



@Service("ePWireService")
public class EPWireServiceImpl implements EPWireService {
	@Autowired
	private EPWireDao ePWireDao;
	
	@Override
	public EPWireEntity queryObject(String guid){
		return ePWireDao.queryObject(guid);
	}
	
	@Override
	public List<EPWireEntity> queryList(Map<String, Object> map){
		return ePWireDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return ePWireDao.queryTotal(map);
	}
	
	@Override
	public void save(EPWireEntity ePWire){
        if(ePWire.getGuid()==null||ePWire.getGuid().equals("")) {

		    ePWire.setGuid(UUID.randomUUID().toString());
        }
		ePWireDao.save(ePWire);
	}
	
	@Override
	public void update(EPWireEntity ePWire){
		ePWireDao.update(ePWire);
	}
	
	@Override
	public void delete(String guid){
		ePWireDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		ePWireDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<EPWireEntity> entities) {
		for (EPWireEntity d : entities) {
			if (d.getPWDatastate().equals("删除")) {
				ePWireDao.delete(d.getGuid());
			} else {
				EPWireEntity epWireEntity = ePWireDao.queryObject(d.getGuid());
				if (epWireEntity == null) {
					ePWireDao.save(d);
				} else {
					ePWireDao.update(d);
				}
			}
		}
	}
}
